<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="../common/base.jsp"%>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
    <meta http-equiv="expires" content="0">
    <title>优惠券</title>
    <link rel="stylesheet" type="text/css" href="${base}/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="${base}/plugin/dropload/dropload.css">
    <link rel="stylesheet" type="text/css" href="${base}/css/global.css?version=${version}">
    <link rel="stylesheet" type="text/css" href="${base}/css/takecar.css?version=${version}">
    <style>
        #quxiao{
            width: 90%;
            margin: 0 auto;
            text-align: center;
            color: #4f5a67;
            border-radius: 4px;
            border: solid 1px #4f5a67;
            line-height: 40px;
            height: 40px;
            font-size: 20px;
            margin-bottom: 10px;
        }
        #queren{
            width: 90%;
            margin: 0 auto;
            margin-top: 10px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            border-radius: 4px;
            background-color: #4f5a67;
            font-size: 20px;
            color: #fff;
        }
        .btns-sub{
            position: fixed;
            left: 0;
            right: 0;
            bottom: 0;
            background: #fff;
            padding-bottom: 10px;
        }
        .c-coupon{
            /*padding-bottom: 120px;*/
        }
        .l-coupon{
            position: static;
        }
        .couponlist .e-radio +label:after, .couponlist .e-radio:checked +label:after{
            content: '';
            display: none;
        }
    </style>
</head>
<body class="c-coupon couponlist">
<div class="l-coupon">
    <div class="m-coupon">
        <%--<div class="coupon-first">--%>
            <%--<input type="radio" name="test" value="" id="not" class="e-radio">--%>
            <%--<label for="not">--%>
                <%--<span>不使用电子券</span>--%>
                <%--&lt;%&ndash;<span style="text-align: right; padding-right: 10px;"><input type="radio" name="test"></span>&ndash;%&gt;--%>
            <%--</label>--%>
        <%--</div>--%>
        <ul class="coupon-ul" id="coupon-ul">

        </ul>
    </div>
</div>
<%--<div class="btns-sub">--%>
    <%--<div id="quxiao">取消</div>--%>
    <%--<div id="queren">确认</div>--%>
<%--</div>--%>

<script type="text/html" id="order-list-html">
    <li>
        <input type="radio" name="test" id="{{uuid}}" value="{{uuid}}" class="e-radio">
        <label for="{{uuid}}">
            <div class="coupon-money">
                <p>{{moneys}}<span>{{typeName}}</span></p>
            </div>
            <div class="fenge-y">
                <div></div>
            </div>
            <div class="coupon-text">
                <p>{{name}}</p>
                <div>
                    <%--<p>有效期至{{useEndTime}}</p>--%>
                    <p>有效期至{{aliveTime}}</p>
                    <p>{{astrictStr}}</p>
                    <p>{{cityNames}}</p>
                </div>
            </div>
            <%--<div class="coupon-radio">--%>
            <%--<input type="radio" name="test">--%>
            <%--</div>--%>
        </label>
    </li>
</script>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script type="text/javascript" src="${base}/plugin/dropload/dropload.min.js"></script>
<script type="text/javascript" src="${base}/plugin/layer-v3.0.3/layer.js"></script>
<script type="text/javascript" src="${base}/js/localStorageOpt.js"></script>
<script type="text/javascript" src="${base}/js/utils.js?version=${version}"></script>
<script>
    (function () {
        var yun=new yueajax( "${openId}");
        yun.listHtml=$('#order-list-html').html();
        yun.listCoupon={};
        var page=0;
        window.coupon={
            nowPage:1,
        };
//            console.log(coupon)
        function getCouponList(page,me){
            yun.ajax_md5(
                    {
                        nowPage:page
                    },
                    '${base}/api/v1/passenger/token/coupon/listUsable',
                    function (data) {
                        var h=''
                        var d=data.data;
                        for(var i=0 ;i<d.length;i++){
                            var di=d[i];
                            di.cityNames=!di.cityNames?'不限城市':'限'+di.cityNames+'使用';
                            if(di.type==1){
                                di.moneys=di.money;
                                di.astrictStr=di.astrict!=null ? '单笔满'+di.astrict+'使用':'无门槛';
                                di.typeName='元';
                            }else{
                                di.typeName='折';
                                di.moneys=di.discount;
                                di.astrictStr='';
                                if(di.astrict!=null){
                                    di.astrictStr+='单笔满'+di.astrict+'使用';
                                }
                                if(di.highestMoney!=null){
                                    if(di.astrict!=null){
                                        di.astrictStr+=',最高抵扣'+di.highestMoney+'元';
                                    }else{
                                        di.astrictStr+='最高抵扣'+di.highestMoney+'元';
                                    }
                                }
                                if(di.astrict==null || di.highestMoney==null){
                                    di.astrictStr="无门槛"
                                }
                            }
                            di.useEndTime=(new Date(di.useEndTime)).format('YYYY-MM-DD');
                            h+=yun.rendering(yun.listHtml,di);
                            yun.listCoupon[di.uuid]=di;
                        }

                        if(d.length==0){
//                            $('#coupon-ul').append(" <li style='text-align: center;'><label>暂无优惠券</label> </li>");
//                            $('#coupon-ul').html(yun.listHtml);
                            me.lock();
                            me.noData();
                            me.resetload();
                            return;
                        }else{
                            $('#coupon-ul .dropload-down').before(h);
                        }

                        if(d.length<10){
                            me.lock();
                            me.noData();
                            me.resetload();
                        }
                        me.resetload();
                    },
                    function (data) {
                        layer.msg(data.msg)
                        me.lock();
                        me.noData();
                        me.resetload();
                    }
            );
        }
        $('#coupon-ul').dropload({
            scrollArea : window,
            distance:50,
            loadDownFn : function(me){
                page++;
                getCouponList(page,me)

            },

        });
        var wt=window.top;
        $('#queren').click(function(){
            var di=$('.e-radio:checked').val();

            wt.setCouInfo(yun.listCoupon[di] || null);
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        });

        $('#quxiao').click(function(){
            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.close(index);
        })
    })()
</script>
</body>
</html>
